package com.business_clean.ui.activity.project;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import com.business_clean.R;
import com.business_clean.app.App;
import com.business_clean.app.base.BaseActivity;
import com.business_clean.app.base.BaseAgentWebActivity;
import com.business_clean.app.config.AsyncRequestUtil;
import com.business_clean.app.ext.CommonUtils;
import com.business_clean.app.network.NetUrl;
import com.business_clean.app.uitl.ActivityForwardUtil;
import com.business_clean.databinding.ActivityCompanyProjectBinding;
import com.business_clean.ui.activity.classes.ClassesMangerActivity;
import com.business_clean.ui.activity.custom.CommonContactManagementActivity;
import com.business_clean.ui.activity.group.GroupManagerActivity;
import com.business_clean.ui.adapter.custom.contact.ContactManagerAdapter;
import com.just.agentweb.WebChromeClient;
import com.just.agentweb.WebViewClient;

import org.jetbrains.annotations.Nullable;

import me.hgj.mvvmhelper.base.BaseViewModel;

public class CompanyProjectDetailActivity extends BaseAgentWebActivity<BaseViewModel, ActivityCompanyProjectBinding> {

    private String project_uuid;
    private String project_name;

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        if (getIntent() != null && getIntent().getExtras() != null) {
            project_uuid = getIntent().getExtras().getString("uuid");
            project_name = getIntent().getExtras().getString("project_name");
        }
        mDatabind.tabbar.setRightText("编辑");
    }


    @Override
    public void onBindViewClick() {
        mDatabind.tabbar.setOnRightTextClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("uuid", project_uuid);
                ActivityForwardUtil.startActivity(AddCompanyProjectActivity.class, bundle);
            }
        });
//        mDatabind.butCantacts.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Bundle bundle = new Bundle();
//                bundle.putString("project_uuid", "" + project_uuid);
//                bundle.putString("project_name", "" + project_name);
//                ActivityForwardUtil.startActivity(CommonContactManagementActivity.class, bundle);
//            }
//        });
        mDatabind.butClasses.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("project_uuid", "" + project_uuid);
                bundle.putString("project_name", "" + project_name);
                ActivityForwardUtil.startActivity(ClassesMangerActivity.class, bundle);
            }
        });
        mDatabind.butGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("project_uuid", "" + project_uuid);
                bundle.putString("project_name", "" + project_name);
                ActivityForwardUtil.startActivity(GroupManagerActivity.class, bundle);
            }
        });
        mDatabind.butEditProject.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("uuid", project_uuid);
                ActivityForwardUtil.startActivity(AddCompanyProjectActivity.class, bundle);
            }
        });

    }

    @Override
    public void initObserver() {
        //监听是否需要刷新
        App.appViewModelInstance.getRefreshProjectManagerList().observe(this, new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {
                mAgentWeb.get().getUrlLoader().reload();
            }
        });

    }

    @Override
    protected ViewGroup getAgentWebParent() {
        return mDatabind.llWeb;
    }


    @Override
    protected String getUrl() {
        return CommonUtils.getWebUrlHost() + NetUrl.WEB_PROJECT_DETAIL_URL + "project_uuid=" + project_uuid;
    }
}